This is a script for manipulating with sections/masterpages.
Please refer to the documentation for more detail.
This script is a FULL version, not a demo.
If you found a bug in the script, let me know. All bug fixes and
updates are free for the registered users
NOTE! This script works only with FW 4, if you have versions 1,2 or
3, please use FWSectionsc1_2.lha instead!!! NOTE!
If you would like something to say, e-mail is: ffpecjak@uni-lj.si
*/
options results;centriraj="rt_reqpos = reqpos_centerscr";call addlib("rexxreqtools.library",0,-30);call addlib("rexxsupport.library",0,-30);status "filename";imedok=result;status "pathname";imedok1=result;imedok1=imedok1||'.sc';NL='0a'x;call rtezrequest("This script will heavily modify your document!!!"||NL||"We recommend that you save your work first","Proceed|Save as|Exit",,centriraj);if rtresult=3 then exit;if rtresult=2 then saveas;if rtresult=0 then exit;call rtezrequest("In which commands are you interested?","Sections|Master Page|Styles",,centriraj);if rtresult=1 then poglavje=1;if rtresult=2 then poglavje=2;if rtresult=0 then call stylescor;if poglavje=1 then;do;call rtezrequest("What do you want to do with sections?","Move|Copy|Swap|Exit",,centriraj);if rtresult=1 then;do;naredi=2;kajnajdelam=1;end;if rtresult=2 then naredi=5;if rtresult=3 then naredi=3;if rtresult=0 then exit;add=3;call naredispisek;if add=0 then;do;prisili=0;call odvzemi;end;if add=1 then call dodaj;if naredi=2|naredi=5 then;do;if naredi=5 then;do;newstring=rtgetstring("new","Enter name of the new section","Section Script by Jernej Pecjak",,centriraj);kakoime='"'||newstring||'"';kajnajdelam=0;end;getsectionsetup NAME;imepoglavja='"'||result||'"';call vizualno;gotosection imekam;newsection text name "temporary" polozi;call naredispisek;call dodaj;ime1=imeodkod;ime2="temporary";call premaknigfxtotal;gotosection imeodkod;editbody;if kajnajdelam=1 then;do;prisili=1;call zbrisipoglavje;call naredispisek;call odvzemi;gotosection "temporary";sectionsetup NEWNAME imeodkod;redraw;end;else;do;gotosection "temporary";sectionsetup NEWNAME kakoime;end;end;if naredi=3 then;do;getsectionsetup NAME;imepoglavja='"'||RESULT||'"';call vizualnopod1;imezac=imeodkod;call vizualnopod1;imekam=imeodkod;imeodkod=imezac;if imekam=imeodkod then;do;call rtezrequest("Are you joking?"||NL||"That are the same sections","Exit",,centriraj);exit;end;gotosection spisek.1;newsection TEXT name "temporary" after;ime1=imeodkod;ime2="temporary";call premaknigfxtotal;gotosection imeodkod;call pobrisipoglavje;ime1=imekam;ime2=imeodkod;call premaknigfxtotal;gotosection imekam;call pobrisipoglavje;ime1="temporary";ime2=imekam;call premaknigfxtotal;gotosection "temporary";removesection "temporary" force;gotosection imeodkod;sectionsetup NEWNAME "temporary";gotosection imekam;sectionsetup NEWNAME imeodkod;gotosection "temporary";sectionsetup NEWNAME imekam;end;end;if poglavje=2 then;do;call rtezrequest("What do you want to do with masterpages?","Copy|Move|Swap|Correct|Undo correct|Exit",,centriraj);if rtresult=1 then naredi=1;if rtresult=2 then naredi=2;if rtresult=3 then naredi=3;if rtresult=4 then naredi=4;if rtresult=5 then naredi=5;if rtresult=0 then EXIT;if naredi=1 then;do;kopiraj=1;call delozmasterji;end;if naredi=2 then;do;kopiraj=0;call delozmasterji;end;if naredi=3 then call zamenjajmasterpage;if naredi=4 then;do;call naredispisek;if exists(imedok1) then;do;end;else;do;open(posnemi,imedok1,'Write');call lineout(posnemi,'This file is needed for correcting the master page bug!');call lineout(posnemi,'Do not delete it or the master page bug will mess up');call lineout(posnemi,'Your document even further!!!');do x=2 for i-1;y=x-1;call lineout(posnemi,spisek.y);call lineout(posnemi,'0');end;call close(posnemi);end;call preberiprefs;do x=2 for i-1;gotosection spisek.x;gotopage 9999;status "page";strani=result;strani2=strani/2;if strani2 ~=trunc(strani2,0) then;do;if polozaj.x=0 then novpolozaj.x=1;else novpolozaj.x=0;end;else;do;if polozaj.x=1 then novpolozaj.x=1;else novpolozaj.x=0;end;end;alijesprememba=0;do x=2 for i-1;if novpolozaj.x=1 then;do;if polozaj.x=0 then;do;polozaj.x=1;end;else;do;polozaj.x=0;end;y=x-1;gotosection spisek.y;aa=y;bb=x;cc=i;call zamenjajmasterpage;y=aa;x=bb;i=cc;alijesprememba=1;end;end;OPEN(posnemi,imedok1,'Write');call lineout(posnemi,'This file is needed for correcting the master page bug!');call lineout(posnemi,'Do not delete it or the master page bug will mess up');call lineout(posnemi,'Your document even further!!!');if alijesprememba=0 then;do;rtezrequest("Your master pages are correct!"||NL||"You don't need to save changes","Understood",,centriraj);exit;end;do x=2 for i-1;y=x-1;call lineout(posnemi,spisek.y);call lineout(posnemi,polozaj.x);end;call close(posnemi);call rtezrequest("You have to save your changed document now!"||NL||"If you don't save it, you will mess up your document later!","Save!|Don't save",,centriraj);if rtresult=0 then;do;rtezrequest("You have been warned!"||NL||"Your master pages will behave very strange!","EXIT",,centriraj);exit;end;saveas;end;if naredi=5 then;do;call naredispisek;if exists(imedok1) then;do;call preberiprefs;do x=2 for i-1;if polozaj.x=1 then;do;y=x-1;gotosection spisek.y;aa=y;bb=x;cc=i;call zamenjajmasterpage;y=aa;x=bb;i=cc;end;end;delete(imedok1);call rtezrequest("Undo processed OK!"||NL||"Your master pages are back the way"||NL||"they were before you first called the script","OK",,centriraj);end;else;do;call rtezrequest("You didn't correct master pages yet!","Exit",,centriraj);exit;end;end;end;EXIT;Damjana:;Graphictool;FirstObject;stevec=0;do until result=0;objectid=result;stevec=stevec+1;setobjectparams objectid LINKED samopot.stevec;selectobject objectid;x=x.stevec;y=y.stevec;visina=visina.stevec;sirina=sirina.stevec;stran=stran.stevec;setobjectcoords objectid stran x y visina sirina;redraw;NextObject objectid;end;redraw;return;Damjanafix:;FirstObject selected;stevec=0;do until result=0;objectid=result;stevec=stevec+1;objectid.stevec=objectid;NextObject objectid SELECTED;end;do haj=1 for stevec;selectobject objectid.haj;getobjectcoords 0;PARSE VAR Result stran x y visina sirina;x=x-0.3175;y=y-0.3175;setobjectcoords 0 stran x y visina sirina;setobjectparams 0 LINKED samopot.stevec;end;redraw;return;Damjana1:;stevec=0;GraphicTool;FirstObject;niobjekta=result;do until result=0;stevec=stevec+1;objectid=result;getobjectparams objectid LINKED;samopot.stevec=result;getobjectcoords objectid;parse var Result stran x y visina sirina;stran.stevec=stran;x.stevec=x;y.stevec=y;visina.stevec=visina;sirina.stevec=sirina;NextObject objectid;end;FirstObject;niobjekta=result;do until result=0;objectid=result;SelectObject objectid MULTIPLE;NextObject objectid;end;redraw;return niobjekta;ustvaripoglavje:;o=i;i=1;gotosection spisek.i;i=o;newsection text name "temp" after;i=0;spisek.i='temp';i=o;gotosection imepoglavja;return 0;PopraviGfx:;call bodymaster;call desnimaster;call levimaster;return;DesniMaster:;gotosection spisek.i;editrightmaster;Damjana1();cut;gotosection spisek.j;editrightmaster;if niobjekta>0 then;do;paste;call Damjana;end;return;LeviMaster:;gotosection spisek.i;editleftmaster;Damjana1();cut;gotosection spisek.j;editleftmaster;if niobjekta>0 then;do;paste;call Damjana;end;return;Bodymaster:;gotosection spisek.i;Damjana1();cut;gotosection spisek.j;if niobjekta>0 then;do;paste;call damjana;end;return;odvzemi:;tu=i+1;if spisek.tu=imepoglavja then preskok=1;else preskok=0;if preskok=5 then;do;i=1;do until spisek.i=imepoglavja;i=i+1;end;call ustvaripoglavje;do until i=0;niobjekta=1;i=i-1;j=i+1;call popravigfx;end;removesection "temp" force;gotosection imepoglavja;editbody;end;return;dodaj:;stspiskov=i;i=1;getsectionsetup NAME;imepoglavja='"'||result||'"';if spisek.i=imepoglavja then abk=1;else abk=0;if abk=5 then;do;do until spisek.i=imepoglavja;niobjekta=1;i=i+1;j=i-1;call popravigfx;end;gotosection imepoglavja;editbody;end;return;zbrisipoglavje:;do;getsectionsetup NAME;imepoglavja='"'||result||'"';if prisili=1 then;removesection imepoglavja force;else;removesection imepoglavja;getsectionsetup NAME;imepoglavja='"'||result||'"';end;return;dodajpoglavje:;ime=rtgetstring("main","Enter name of the new section","Section Script by Jernej Pecjak",,centriraj);call rtezrequest("Do you want to insert it AFTER or BEFORE the current section?","After|Before",,centriraj);if rtresult=1 then potem=1;if rtresult=0 then potem=0;if potem=1 then NewSection text name ime after;if potem=0 then NewSection text name ime before;return;testirajobstoj:;prav=0;do x=1 for i;if upper(spisek.x)=upper(test) then prav=1;end;if prav=0 then;do;call rtezrequest("The section " test " does not exist!!!","Try again","Exit",,centriraj);if rtresult=0 then exit;naredilsem=0;end;else naredilsem=1;return;vizualno:;call vizualnopod1;call vizualnopod2;return;vizualnopod1:;start=1;if i<6 then;kolikokrat=i;else kolikokrat=5;izberi=0;if i<6 then nenaredi=0;else nenaredi=1;nenaredi1=1;do until izberi=1;testiraj="";testiraj2="Back|";konec=start+kolikokrat;do xx=start for kolikokrat;yy=i-xx+1;testiraj=testiraj xx||'.'||spisek.yy||NL;if xx<konec-1 then;testiraj2=testiraj2||xx||'|';else testiraj2=testiraj2||xx||'|Forward|Exit';end;call rtezrequest("Which section would you like to move??"||NL||testiraj,testiraj2,,centriraj);izberi=1;if rtresult=0 then exit;if rtresult=kolikokrat+2 then;do;if nenaredi=1 then;do;start=start+5;if i>start+5 then;do;kolikokrat=5;nenaredi=1;nenaredi1=1;end;else;do;nenaredi=0;kolikokrat=i-start+1;end;end;izberi=0;end;if rtresult=1 then;do;if nenaredi1=1 then;do;start=start-5;if start>0 then;do;kolikokrat=5;nenaredi=1;nenaredi1=1;end;else;do;if start=-4 then start=1;if i<5 then kolikokrat=i;else kolikokrat=5;nenaredi1=0;end;end;izberi=0;end;y=i-(rtresult+start-3);end;if rtresult=0 then exit;imeodkod=spisek.y;imeodkod1=y;return;vizualnopod2:;start=1;if i<6 then;kolikokrat=i;else kolikokrat=5;izberi=0;if i<6 then nenaredi=0;else nenaredi=1;nenaredi1=1;do until izberi=1;testiraj="";testiraj2="Back|";konec=start+kolikokrat;do xx=start for kolikokrat;yy=i-xx+1;testiraj=testiraj||' '||xx||'.'||NL||spisek.yy||NL;testiraj2=testiraj2||xx||'|';end;testiraj=testiraj||' '||xx||'.';testiraj2=testiraj2||xx||'|Forward|Exit';call rtezrequest("Where would you like to move the section?"||NL||testiraj,testiraj2,,centriraj);izberi=1;if rtresult=0 then exit;if rtresult=kolikokrat+3 then;do;if nenaredi=1 then;do;start=start+5;if i>start+5 then;do;kolikokrat=5;nenaredi=1;nenaredi1=1;end;else;do;nenaredi=0;kolikokrat=i-start+1;end;end;izberi=0;end;if rtresult=1 then;do;if nenaredi1=1 then;do;start=start-5;if start>0 then;do;kolikokrat=5;nenaredi=1;nenaredi1=1;end;else;do;if start=-4 then start=1;if i<5 then kolikokrat=i;else kolikokrat=5;nenaredi1=0;end;end;izberi=0;end;y=i-(rtresult+start-3);end;if y=i then;nemogoce=1;else;nemogoce=0;y=y+1;polozi=after;if nemogoce=1 then;do;y=y-1;polozi=before;end;imekam=spisek.y;testiraj=y-1;if (kajnajdelam=1)&((spisek.y=imeodkod)|(spisek.testiraj=imeodkod)) then;do;rtezrequest("The section is already there!!!","Exit",,centriraj);exit;end;return;tekstualno:;naredilsem=0;do while naredilsem=0;call rtgetstring("new","Enter name of the new section to move/copy/swap","Section Script by Jernej Pecjak",,centriraj);imeodkod='"'||newstring||'"';test=imeodkod;call testirajobstoj;end;naredilsem=0;do while naredilsem=0;requesttext '"Section MOVE/COPY/SWAP by Jernej Pecjak" "Before or After which section to move?" ""';imekamtemp='"'||result||'"';test=imeodkod;call testirajobstoj;end;if imeodkod=imekamtemp then;do;call rtezrequest("It is already there!","Exit",,centriraj);exit;end;ff=0;spisek.0="abcdefg";do until upper(imekamtemp)=upper(spisek.ff);ff=ff+1;end;call rtezrequest("Do you want the section you are moving to be"||NL||"AFTER or BEFORE the one you selected?","After|Before|ABORT",,centriraj);if result=0 then exit;if result=1 then;do;polozi=after;ff=ff-1;end;if result=2 then;do;polozi=before;ff=ff+1;end;if upper(spisek.ff)=upper(imeodkod) then;do;call rtezrequest("It is already there!","Exit",,centriraj);exit;end;imekam=imekamtemp;return;naredispisek:;getsectionlist ".";spisek=result;i=0;newspisek=1;do until newspisek=0;i=i+1;odrezi=lastpos('.',spisek);dolzina=length(spisek);if odrezi=0 then odrezi= dolzina;newspisek= dolzina-odrezi;if newspisek=0 then spisek.i='"'||right(spisek, dolzina)||'"';else spisek.i='"'||right(spisek,newspisek)||'"';spisek= delstr(spisek,odrezi);end;return;testnacin:;if nacin=1 then editbody;if nacin=2 then editrightmaster;if nacin=3 then editleftmaster;return;premaknigfxtotal:;nacin=1;call premaknigfx;nacin=2;call premaknigfx;nacin=3;call premaknigfx;return;premaknigfx:;gotosection ime1;call testnacin;texttool;selectall;extract;if result>"" then nare=1;else nare=0;selectall;if nare=1 then;do;cut;paste;end;else copy;redraw;gotosection ime2;call testnacin;if nare=1 then paste;gotosection ime1;call testnacin;Damjana1();copy;redraw;gotosection ime2;call testnacin;if niobjekta>0 then;do;paste;call damjana;end;return;tekstualnozam:;naredilsem=0;do while naredilsem=0;call rtgetstring(,"Enter name of the section to swap","Section Script by Jernej Pecjak",,centriraj);imeodkod='"'||newstring||'"';test=imeodkod;call testirajobstoj;end;naredilsem=0;do while naredilsem=0;call rtgetstring(,"Swap with which section","Section Script by Jernej Pecjak",,centriraj);imekam='"'||newstring||'"';test=imeodkod;call testirajobstoj;end;if imeodkod=imekam then;do;call rtezrequest("It is already there!","Exit",,centriraj);exit;end;return;pobrisipoglavje:;texttool;selectall;clear;graphictool;damjana1();clear;editleftmaster;texttool;selectall;clear;graphictool;damjana1();clear;editrightmaster;selectall;clear;graphictool;damjana1();clear;return;brisidesnimaster:;editrightmaster;texttool;selectall;clear;graphictool;damjana1();clear;editbody;return;brisilevimaster:;editleftmaster;texttool;selectall;clear;graphictool;damjana1();clear;editbody;return;kopirajmaster:;if between=1 then gotosection imeodkod;if odkod=levi then editleftmaster;else editrightmaster;texttool;selectall;extract;if result>"" then nare=1;else nare=0;selectall;if nare=1 then;do;cut;paste;if kopiraj=0 then cut;end;else copy;redraw;if between=1 then gotosection imekam;if kam=levi then editleftmaster;else editrightmaster;if nare=1 then paste;if between=1 then gotosection imeodkod;if odkod=levi then editleftmaster;else editrightmaster;graphictool;damjana1();if kopiraj=1 then copy;else cut;if between=1 then gotosection imekam;if kam=levi then editleftmaster;else editrightmaster;if niobjekta>0 then;do;paste;call damjana;end;editbody;return;delozmasterji:;call rtezrequest("Copy what?","L->R|R->L|Between",,centriraj);if rtresult=1 then;do;kaj=1;call rtezrequest("Delete right master?","Yes|No",,centriraj);if rtresult=1 then call brisidesnimaster;odkod=levi;kam= desni;between=0;call kopirajmaster;end;if rtresult=2 then;do;kaj=2;call rtezrequest("Delete left master?","Yes|No",,centriraj);if rtresult=1 then call brisilevimaster;odkod= desni;kam=levi;between=0;call kopirajmaster;end;if rtresult=0 then;do;call naredispisek;getsectionsetup NAME;imepoglavja='"'||result||'"';call rtezrequest("How would you like to select the masters to copy","Click|Text",,centriraj);if rtresult=1 then;do;kaj=3;call vizualnopod1;imezac=imeodkod;call vizualnopod1;imekam=imeodkod;imeodkod=imezac;end;else call tekstualnozam;call rtezrequest("Which masterpage do you want to copy?","Left|Right|Both",,centriraj);if rtresult=1 then mpage=1;if rtresult=2 then mpage=2;if rtresult=0 then mpage=3;if mpage=1 then;do;kam=levi;odkod=levi;call zbrisidestination;end;if mpage=2 then;do;kam= desni;odkod= desni;call zbrisidestination;end;if mpage=3 then;do;kam=levi;odkod=levi;between=1;call zbrisidestination;call kopirajmaster;kam= desni;odkod= desni;gotosection imekam;call brisidesnimaster;end;between=1;call kopirajmaster;end;return;zbrisidestination:;call rtezrequest("Delete destination before copy/move?","Yes|No",,centriraj);if rtresult=1 then;do;gotosection imekam;if kam=levi then call brisilevimaster;else call brisidesnimaster;end;return;LineOut:PROCEDURE;PARSE ARG filehandle,str;len=WRITELN(filehandle,str);IF (len ~=LENGTH(str)+1) THEN;DO;ShowMessage 1 1 '"Error!" "" "" "OK" "" ""';CALL CLOSE(filehandle);EXIT;END;return;zamenjajmasterpage:;do;getsectionsetup NAME;imepoglavja=result;call naredispisek;gotosection spisek.1;newsection text name "temporary" after;gotosection imepoglavja;editleftmaster;kam=levi;odkod=levi;imeodkod=imepoglavja;imekam="temporary";between=1;call kopirajmaster;odkod= desni;kam=levi;imeodkod=imepoglavja;imekam=imepoglavja;gotosection imepoglavja;call brisilevimaster;call kopirajmaster;call brisidesnimaster;odkod=levi;kam= desni;imeodkod="temporary";imekam=imepoglavja;call kopirajmaster;removesection "temporary" force;gotosection imepoglavja;end;return;preberiprefs:;open(posnemi,imedok1,'Read');call readln(posnemi);call readln(posnemi);call readln(posnemi);do x=2 for i-1;call readln(posnemi);call readln(posnemi);polozaj.x=result;end;call close(posnemi);return;stylescor:;call rtezrequest("Sorry, this function isn't implemented yet","Quit",,centriraj);exit;call naredispisek;iscistyle=rtgetstring("Body","Enter name of the style you would like to change","Font restore by Jernej Pecjak",,centriraj);type '0a'x;cursor up;stylesheet iscistyle;status fontname;iscifont=result;status fontsize;size=result;cursor down;backspace;novi='0a'x;do zz=1 for 2;gotosection spisek.zz;movetopara 1 0;status fontname;immme=result;x=0;konec=0;nasel=0;co=0;dolzina.x=0;status stylesheet;tempor=result;if upper(tempor)=upper(iscistyle) then naprej=0;else naprej=1;do until konec=1;status fontname;immme=result;status fontsize;size1=result;if (upper(immme) ~=upper(iscifont))|(size1 ~=size) then;do;status stylesheet;tempor=result;if upper(tempor)=upper(iscistyle) then;do;if nasel=0 then;do;x=x+1;dolzina.x=0;call parametri(x);cursor left;getsectionsetup NAME;ime.x=result;status parapos;parse var result para.x pos.x;cursor right;end;nasel=1;dolzina.x=dolzina.x+1;end;else;do;status parapos;parse var result para pos;para=para+1;movetopara para 1;nasel=0;end;end;else nasel=0;if nasel=0 then;do;end;cursor right;extract;if result='0a'x then;do;status parapos;parse var result para pos;cursor right;status parapos;parse var result para1 pos;if para=para1 then konec=1;end;end;end;call rtezrequest("End of paragraph!","OK",,centriraj);do y=1 for x;call rtezrequest("Text found at position" ime.x para.y pos.y dolzina.y,"OK",,centriraj);end;call rtezrequest("Change your body text!","OK",,centriraj);do y=1 for x;gotosection ime.y;movetopara para.y pos.y;shiftdown;do z=1 for dolzina.y;cursor right;end;shiftup;call setparametri(y);end;exit;return;parametri:;parse arg stevec;Status FontSize;Fontsize.stevec=result;Status FontLeading;Leading.stevec=result;Status FontWidth;Width.stevec=result;Status FontOblique;Oblique.stevec=result;Status FontPosition;Position.stevec=result;Status FontCase;Case.stevec=result;Status FontColor;Color.stevec=result;Status FontStyle;Style.stevec=result;Status FontPath;Font.stevec=result;Status Spacing;Spacing.stevec=result;return;setparametri:;parse arg stevec;fontsize Fontsize.stevec;oblique Oblique.stevec;font Font.stevec;return yy